package com.hearwego;

import java.util.List;

import com.utilities.HWGSQLiteHelper;
import com.utilities.Informacion;

import android.app.ProgressDialog;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

public class DescripcionFragment extends Fragment {
	
	ProgressDialog dialog;
	View view;
	List<Informacion> informacion;
	TextView titulo_desc, descripcion;
	HWGSQLiteHelper usdbh;
	SQLiteDatabase db;
	String stringTitulo_desc, stringDescripcion;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		new LoagGastos().execute("");
		view = inflater.inflate(R.layout.description_fragment, container, false);
		return view;
	}
	
	class LoagGastos extends AsyncTask<String, String, String>{
    	int zeroGastos = -1;
    	
    	@Override
    		protected void onPreExecute() {
    			super.onPreExecute();
    		}
    	
		@Override
		protected String doInBackground(String... params) {
			usdbh =new HWGSQLiteHelper(getActivity(), "DBHWG", null, 1);
	        db = usdbh.getWritableDatabase();
	        if(db != null)
	        {
	        	Cursor c = db.rawQuery("SELECT * FROM Detalle", null);
	        	if (c.moveToFirst()) {
	        		stringTitulo_desc = c.getString(2);
	        		stringDescripcion = c.getString(18);
	        		
	        		Log.i("BD",stringTitulo_desc + stringDescripcion );
	        	}else{
	        		zeroGastos = 0;
	        	}
	        	db.close();
	        }
			return null;
		}
		
		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			
			if(!stringTitulo_desc.equals("null")){
				titulo_desc = (TextView) view.findViewById(R.id.titulo_descr);
				titulo_desc.setVisibility(View.VISIBLE);
				titulo_desc.setText(stringTitulo_desc);
			}
			
			if(!stringDescripcion.equals("null")){
				descripcion = (TextView) view.findViewById(R.id.descrip);
				descripcion.setVisibility(View.VISIBLE);
				descripcion.setText(stringDescripcion);
			}
			
//			Toast.makeText(getActivity().getApplicationContext(), "Datos traidos de BD", Toast.LENGTH_SHORT).show();
		}
    }
}
